import { createVNode, render, ComponentPublicInstance, VNode } from "vue";
import CommonModal from "@/components/dialog";
const instances: any[] = [];
export default function useMyDialog(option?: any) {
  const props = {
    ...option,
  };
  const tempVm: any = instances.find((item) => {
    return item.props.title === option.title;
  });

  if (tempVm) {
    // 有缓存 使用缓存
    (tempVm.component as any).exposeProxy.onVisible(true);
  } else {
    const vm = createVNode(CommonModal, props);
    const container = document.createElement("div");
    render(vm, container);
    document.body.appendChild(container);
    // 调用内部方法
    (vm.component as any).exposeProxy.onVisible(true);
    instances.push(vm);
  }
}
